package com.zl.smartmall.library.po;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 订单确认页数据
 * @author 陈希然
 *
 */
public class OrderConfirmationInfo {

	private double totalPrice;
	private int totalGold;
	private int maxUseGold;
	private double goldToMoneyRatio;
	private int postage;
	private String storeHouse;
	private DeliveryAddress deliveryAddress;
	private List<PayInfo> payInfos;
	private List<OrderCommoditiesInfo> productInfos;
	private int cmid;
	private int houseid;
	private String cmname;

	public int getHouseid() {
		return houseid;
	}



	public String getCmname() {
		return cmname;
	}



	public void setHouseid(int houseid) {
		this.houseid = houseid;
	}



	public void setCmname(String cmname) {
		this.cmname = cmname;
	}



	public double getTotalPrice() {
		return totalPrice;
	}

	

	public int getCmid() {
		return cmid;
	}



	public void setCmid(int cmid) {
		this.cmid = cmid;
	}



	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public int getTotalGold() {
		return totalGold;
	}

	public void setTotalGold(int totalGold) {
		this.totalGold = totalGold;
	}

	public int getMaxUseGold() {
		return maxUseGold;
	}

	public void setMaxUseGold(int maxUseGold) {
		this.maxUseGold = maxUseGold;
	}

	public double getGoldToMoneyRatio() {
		return goldToMoneyRatio;
	}

	public void setGoldToMoneyRatio(double goldToMoneyRatio) {
		this.goldToMoneyRatio = goldToMoneyRatio;
	}

	public int getPostage() {
		return postage;
	}

	public void setPostage(int postage) {
		this.postage = postage;
	}

	public String getStoreHouse() {
		return storeHouse;
	}

	public void setStoreHouse(String storeHouse) {
		this.storeHouse = storeHouse;
	}

	public DeliveryAddress getDeliveryAddress() {
		return deliveryAddress;
	}

	public void setDeliveryAddress(DeliveryAddress deliveryAddress) {
		this.deliveryAddress = deliveryAddress;
	}

	public List<PayInfo> getPayInfos() {
		return payInfos;
	}

	public void setPayInfos(List<PayInfo> payInfos) {
		this.payInfos = payInfos;
	}

	public List<OrderCommoditiesInfo> getProductInfos() {
		return productInfos;
	}

	public void setProductInfos(List<OrderCommoditiesInfo> productInfos) {
		this.productInfos = productInfos;
	}
	
	public static OrderConfirmationInfo parse(JSONObject jsonObject) throws JSONException {
		OrderConfirmationInfo orderConfirmationInfo = null;
		if(jsonObject != null && jsonObject.length() > 0) {
			orderConfirmationInfo = new OrderConfirmationInfo();
			orderConfirmationInfo.deliveryAddress = DeliveryAddress.parse(jsonObject.getJSONObject("default_add"));
			orderConfirmationInfo.payInfos = PayInfo.parse(jsonObject.getJSONArray("pay_type"));
			orderConfirmationInfo.productInfos = OrderCommoditiesInfo.parse(jsonObject.getJSONArray("details"));
			orderConfirmationInfo.totalPrice = jsonObject.getDouble("total_prices");
			orderConfirmationInfo.postage = (int) jsonObject.getDouble("postage");
			orderConfirmationInfo.storeHouse = jsonObject.getString("storehouse");
			JSONObject goldObject = jsonObject.getJSONObject("gold");
			if(goldObject != null && goldObject.length() > 0) {
				orderConfirmationInfo.goldToMoneyRatio = goldObject.getDouble("1gold2RMB");//一金豆对应的RMB
				orderConfirmationInfo.totalGold = goldObject.getInt("userTotal");
				orderConfirmationInfo.maxUseGold = goldObject.getInt("orderTotal");
			}
			orderConfirmationInfo.cmid = jsonObject.getInt("cmid");
			orderConfirmationInfo.houseid = jsonObject.getInt("houseid");
			orderConfirmationInfo.cmname = jsonObject.getString("cmname");
		}
		return orderConfirmationInfo;
	}
}
